<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>CLion开发环境配置完全解析 - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="CLion开发环境配置完全解析"><meta property="og:title" content="CLion开发环境配置完全解析" />
<meta property="og:description" content="CLion开发环境配置完全解析" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-12-29T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-12-29T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="CLion开发环境配置完全解析"/>
<meta name="twitter:description" content="CLion开发环境配置完全解析"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" /><link rel="prev" href="https://acking-you.github.io/posts/chatgp%E6%95%99%E6%88%91%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90/" /><link rel="next" href="https://acking-you.github.io/posts/ejson4cpp%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "CLion开发环境配置完全解析",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90\/"
        },"genre": "posts","keywords": "CLion开发环境配置完全解析","wordcount":  10811 ,
        "url": "https:\/\/acking-you.github.io\/posts\/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90\/","datePublished": "2022-12-29T00:00:00+00:00","dateModified": "2022-12-29T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "CLion开发环境配置完全解析"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/c2804a2e21ea79a0b060126b82a9145c.png#pic_center"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/c2804a2e21ea79a0b060126b82a9145c.png#pic_center, https://img-blog.csdnimg.cn/img_convert/c2804a2e21ea79a0b060126b82a9145c.png#pic_center 1.5x, https://img-blog.csdnimg.cn/img_convert/c2804a2e21ea79a0b060126b82a9145c.png#pic_center 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/c2804a2e21ea79a0b060126b82a9145c.png#pic_center"
        title="CLion开发环境配置完全解析" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">CLion开发环境配置完全解析</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/"><i class="far fa-folder fa-fw"></i>开发环境配置</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-12-29">2022-12-29</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 10811 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 22 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#下载与安装">下载与安装</a></li>
    <li><a href="#主题推荐">主题推荐</a></li>
    <li><a href="#编辑器与clang-format设置">编辑器与clang-format设置</a>
      <ul>
        <li><a href="#鼠标滚轮改变字体大小">鼠标滚轮改变字体大小</a></li>
        <li><a href="#clang-format的使用">clang-format的使用</a></li>
      </ul>
    </li>
    <li><a href="#编译工具链设置">编译工具链设置</a>
      <ul>
        <li><a href="#编译工具链的添加与解释">编译工具链的添加与解释</a></li>
        <li><a href="#cmake配置项的添加与解释">cmake配置项的添加与解释</a></li>
      </ul>
    </li>
    <li><a href="#cmake的使用与实战">cmake的使用与实战</a>
      <ul>
        <li><a href="#常用的cmake变量入门">常用的cmake变量（入门）</a></li>
        <li><a href="#常用的cmake命令入门">常用的cmake命令（入门）</a></li>
      </ul>
    </li>
    <li><a href="#ideavim的使用与设置">ideaVim的使用与设置</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="下载与安装">下载与安装</h2>
<p>关于CLion的安装我推荐安装最新的CLion 2022.3之后的版本，因为从这个版本后性能提升了很多，而且还增加了对cmake代码的调试功能，并且对wsl的支持得到进一步的增强，现在有了CLion在windows上使用Linux环境进行开发将是非常简单且舒适的过程。</p>
<p>建议先下载JetBrains家的toolbox然后再进行对应 CLion 的下载，这样也方便你管理与统一配置JB家的所有IDE。</p>
<p>官网链接如下：<a href="https://www.jetbrains.com/zh-cn/toolbox-app/" target="_blank" rel="noopener noreffer">https://www.jetbrains.com/zh-cn/toolbox-app/</a></p>
<p>下载完toolbox后，点开安装CLion 2022.3(或更新的版本) 即可。当然如果你不设置的话，下载完CLion后你会发现它默认安装在C盘，不要慌，toolbox也考虑到了这样的问题。</p>
<p>所以你只需要像下面这样操作：</p>
<ol>
<li><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/e25e4af6db2a462785cc1caee9368725.png"
        data-srcset="https://img-blog.csdnimg.cn/e25e4af6db2a462785cc1caee9368725.png, https://img-blog.csdnimg.cn/e25e4af6db2a462785cc1caee9368725.png 1.5x, https://img-blog.csdnimg.cn/e25e4af6db2a462785cc1caee9368725.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/e25e4af6db2a462785cc1caee9368725.png"
        title="图1" /></li>
<li><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/6e0fbfa1dc4a4fcd8f2822e2cfaabd95.png"
        data-srcset="https://img-blog.csdnimg.cn/6e0fbfa1dc4a4fcd8f2822e2cfaabd95.png, https://img-blog.csdnimg.cn/6e0fbfa1dc4a4fcd8f2822e2cfaabd95.png 1.5x, https://img-blog.csdnimg.cn/6e0fbfa1dc4a4fcd8f2822e2cfaabd95.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/6e0fbfa1dc4a4fcd8f2822e2cfaabd95.png"
        title="图2" /></li>
<li><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/2ba0d80a8a0b407984319dfb20043bbf.png"
        data-srcset="https://img-blog.csdnimg.cn/2ba0d80a8a0b407984319dfb20043bbf.png, https://img-blog.csdnimg.cn/2ba0d80a8a0b407984319dfb20043bbf.png 1.5x, https://img-blog.csdnimg.cn/2ba0d80a8a0b407984319dfb20043bbf.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/2ba0d80a8a0b407984319dfb20043bbf.png"
        title="图3" /></li>
</ol>
<p>更改完这个路径后，它会自动的把数据移动到这个文件夹中，之后下载的所有IDE数据也都会在这个文件夹中了。</p>
<p>我们发现下面还有一个选项是代理，这对某些情况显然是很有用的，如果IDE中的某些东西的下载需要代理，那么可以在这里设置代理。</p>
<p>现在CLion已经下载好了，点开后可能有些人没法正常使用，毕竟大家都是白嫖党()，其实作为学生的我们也完全没有必要花这笔钱，我们去官网申请一个资格即可，之后所有的JB家的产品都可以免费使用一年了，每年需要重新申请一次，申请的网站如下：<a href="https://www.jetbrains.com/shop/eform/students" target="_blank" rel="noopener noreffer">https://www.jetbrains.com/shop/eform/students</a></p>
<p>申请前请用邮箱注册一个jb的账号，注册链接如下：<a href="https://account.jetbrains.com/login" target="_blank" rel="noopener noreffer">https://account.jetbrains.com/login</a></p>
<p>申请有多种方式，学校邮箱如果有的话就很简单了，但是很多大学生没有这个，那么大家可以使用官方文件的方式申请，这种方式稍微麻烦一点，需要去学信网弄一个验证，具体流程如下：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/5a6ba05c3cf145cabf488abab46f5039.png"
        data-srcset="https://img-blog.csdnimg.cn/5a6ba05c3cf145cabf488abab46f5039.png, https://img-blog.csdnimg.cn/5a6ba05c3cf145cabf488abab46f5039.png 1.5x, https://img-blog.csdnimg.cn/5a6ba05c3cf145cabf488abab46f5039.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/5a6ba05c3cf145cabf488abab46f5039.png"
        title="利用官方文件申请" /></p>
<p>上述邮箱同样也需要填入jb账号对应的邮箱，申请完后，一般7天内就会有邮箱通知你成功了，之后所有的jb家的产品都可以通过该账号免费使用。而且这个账号似乎可以供6/7个人同时使用（我不知道上限，但是我给了至少6/7个人）。</p>
<p>至此，CLion应该能够正常打开和使用了，但是打开的界面估计默认是中文，我建议去设置里面调成中文。</p>
<p>方式如下：1.点开设置 2.点开插件 3.点开已安装的插件 4.点击中文的那个插件禁用即可。</p>
<h2 id="主题推荐">主题推荐</h2>
<p>我推荐使用新UI + onedark的组合（我目前所使用的）。</p>
<p>效果如下：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/8db829a09d9f4dc3b55dba03d0a7ac04.png"
        data-srcset="https://img-blog.csdnimg.cn/8db829a09d9f4dc3b55dba03d0a7ac04.png, https://img-blog.csdnimg.cn/8db829a09d9f4dc3b55dba03d0a7ac04.png 1.5x, https://img-blog.csdnimg.cn/8db829a09d9f4dc3b55dba03d0a7ac04.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/8db829a09d9f4dc3b55dba03d0a7ac04.png"
        title="主题1" /></p>
<p>如果你使用的是旧版本的UI，我之前经常使用的主题有以下三个：</p>
<ol>
<li>Atom Material Icons 
效果大概如下，这个一个用于将文件夹颜色更明亮的插件，新UI暂时不可用<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/d66751b1960c424c8fdfb10b270c7120.png"
        data-srcset="https://img-blog.csdnimg.cn/d66751b1960c424c8fdfb10b270c7120.png, https://img-blog.csdnimg.cn/d66751b1960c424c8fdfb10b270c7120.png 1.5x, https://img-blog.csdnimg.cn/d66751b1960c424c8fdfb10b270c7120.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/d66751b1960c424c8fdfb10b270c7120.png"
        title="fileicon" /></li>
<li>material-theme-ui：插件主页 <a href="https://plugins.jetbrains.com/plugin/8006-material-theme-ui" target="_blank" rel="noopener noreffer">https://plugins.jetbrains.com/plugin/8006-material-theme-ui</a></li>
<li>one-dark-theme：插件主页 <a href="https://plugins.jetbrains.com/plugin/11938-one-dark-theme" target="_blank" rel="noopener noreffer">https://plugins.jetbrains.com/plugin/11938-one-dark-theme</a></li>
</ol>
<h2 id="编辑器与clang-format设置">编辑器与clang-format设置</h2>
<h3 id="鼠标滚轮改变字体大小">鼠标滚轮改变字体大小</h3>
<p>Editor -&gt; General -&gt; Change font size with Ctrl+Mouse Wheel 打上勾就行。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/e5909860325a44e1af08e22ef0cb88b1.png"
        data-srcset="https://img-blog.csdnimg.cn/e5909860325a44e1af08e22ef0cb88b1.png, https://img-blog.csdnimg.cn/e5909860325a44e1af08e22ef0cb88b1.png 1.5x, https://img-blog.csdnimg.cn/e5909860325a44e1af08e22ef0cb88b1.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/e5909860325a44e1af08e22ef0cb88b1.png"
        title="mouse control" /></p>
<h3 id="clang-format的使用">clang-format的使用</h3>
<p>关于clang-format是什么，我截一段chatgpt的回答。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/77f9f6bbc4e34dd9ae27b5c53673841f.png"
        data-srcset="https://img-blog.csdnimg.cn/77f9f6bbc4e34dd9ae27b5c53673841f.png, https://img-blog.csdnimg.cn/77f9f6bbc4e34dd9ae27b5c53673841f.png 1.5x, https://img-blog.csdnimg.cn/77f9f6bbc4e34dd9ae27b5c53673841f.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/77f9f6bbc4e34dd9ae27b5c53673841f.png"
        title="clang-format简介" /></p>
<p>CLion是自带clang-format的，你只需要开启即可，他还自动扫描项目根目录下的clang-format文件进行相应的格式化，开启后你每次创建一个新项目他也会自动生产一个clang-format文件到项目根目录，这个文件配置是根据CLion默认的格式化的格式来的，如果想要更改格式化风格，只需要更改clang-formt配置文件即可。</p>
<p>一般来说，我们只需要配置基本风格就行，一个.clang-format文件大概长这样：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/0529243875ad49dd9050d9fae7aabed8.png"
        data-srcset="https://img-blog.csdnimg.cn/0529243875ad49dd9050d9fae7aabed8.png, https://img-blog.csdnimg.cn/0529243875ad49dd9050d9fae7aabed8.png 1.5x, https://img-blog.csdnimg.cn/0529243875ad49dd9050d9fae7aabed8.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/0529243875ad49dd9050d9fae7aabed8.png"
        title=".clang-format" /></p>
<p>一般来说没有什么特殊需求，那么就只需要填写 BasedOnStyle 即可，是Google风格还是LLVM风格还是Microsoft风格，都取决于上述的前三行代码，后面的都可以不用写。我这个配置文件是想要使用Google的格式化风格，但是Googel风格默认的代码边距太短了，所以进行了一系列的调整。</p>
<p>下面是CLion如何开启clang-format，开启后CLion对代码的格式化将会以你项目根目录的clang-format文件为主。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/a6120ebd1ab24c22aa9f147a915a4fde.png"
        data-srcset="https://img-blog.csdnimg.cn/a6120ebd1ab24c22aa9f147a915a4fde.png, https://img-blog.csdnimg.cn/a6120ebd1ab24c22aa9f147a915a4fde.png 1.5x, https://img-blog.csdnimg.cn/a6120ebd1ab24c22aa9f147a915a4fde.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/a6120ebd1ab24c22aa9f147a915a4fde.png"
        title="clang-format1" /></p>
<h4 id="我的-clang-format-配置">我的 .clang-format 配置</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c++" data-lang="c++"><span class="nl">BasedOnStyle</span><span class="p">:</span> <span class="n">Google</span>
<span class="nl">Language</span><span class="p">:</span> <span class="n">Cpp</span>
<span class="nl">AccessModifierOffset</span><span class="p">:</span> <span class="o">-</span><span class="mi">4</span>
<span class="nl">AlignAfterOpenBracket</span><span class="p">:</span> <span class="n">Align</span>
<span class="nl">AlignConsecutiveMacros</span><span class="p">:</span> <span class="n">AcrossComments</span>
<span class="nl">AlignConsecutiveAssignments</span><span class="p">:</span> <span class="n">AcrossComments</span>
<span class="nl">AlignConsecutiveDeclarations</span><span class="p">:</span> <span class="n">AcrossComments</span>
<span class="nl">AlignEscapedNewlines</span><span class="p">:</span> <span class="n">Left</span>
<span class="nl">AlignOperands</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">AlignTrailingComments</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">AllowAllArgumentsOnNextLine</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">AllowAllConstructorInitializersOnNextLine</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">AllowAllParametersOfDeclarationOnNextLine</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">AllowShortBlocksOnASingleLine</span><span class="p">:</span> <span class="n">Never</span>
<span class="nl">AllowShortCaseLabelsOnASingleLine</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">AllowShortFunctionsOnASingleLine</span><span class="p">:</span> <span class="n">All</span>
<span class="nl">AllowShortLambdasOnASingleLine</span><span class="p">:</span> <span class="n">All</span>
<span class="nl">AllowShortIfStatementsOnASingleLine</span><span class="p">:</span> <span class="n">WithoutElse</span>
<span class="nl">AllowShortLoopsOnASingleLine</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">AlwaysBreakAfterDefinitionReturnType</span><span class="p">:</span> <span class="n">None</span>
<span class="nl">AlwaysBreakAfterReturnType</span><span class="p">:</span> <span class="n">None</span>
<span class="nl">AlwaysBreakBeforeMultilineStrings</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">AlwaysBreakTemplateDeclarations</span><span class="p">:</span> <span class="n">Yes</span>
<span class="nl">BinPackArguments</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">BinPackParameters</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">BraceWrapping</span><span class="p">:</span>
  <span class="nl">AfterCaseLabel</span><span class="p">:</span> <span class="nb">false</span>
  <span class="nl">AfterClass</span><span class="p">:</span> <span class="nb">true</span>
  <span class="nl">AfterControlStatement</span><span class="p">:</span> <span class="n">Always</span>
  <span class="nl">AfterEnum</span><span class="p">:</span> <span class="nb">true</span>
  <span class="nl">AfterFunction</span><span class="p">:</span> <span class="nb">true</span>
  <span class="nl">AfterNamespace</span><span class="p">:</span> <span class="nb">false</span>
  <span class="nl">AfterObjCDeclaration</span><span class="p">:</span> <span class="nb">false</span>
  <span class="nl">AfterStruct</span><span class="p">:</span> <span class="nb">true</span>
  <span class="nl">AfterUnion</span><span class="p">:</span> <span class="nb">true</span>
  <span class="nl">AfterExternBlock</span><span class="p">:</span> <span class="nb">true</span>
  <span class="nl">BeforeCatch</span><span class="p">:</span> <span class="nb">true</span>
  <span class="nl">BeforeElse</span><span class="p">:</span> <span class="nb">true</span>

<span class="nl">BreakBeforeBinaryOperators</span><span class="p">:</span> <span class="n">None</span>
<span class="nl">BreakBeforeBraces</span><span class="p">:</span> <span class="n">Custom</span>
<span class="nl">BreakBeforeInheritanceComma</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">BreakInheritanceList</span><span class="p">:</span> <span class="n">BeforeColon</span>
<span class="nl">BreakBeforeTernaryOperators</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">BreakConstructorInitializersBeforeComma</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">BreakConstructorInitializers</span><span class="p">:</span> <span class="n">BeforeColon</span>
<span class="nl">BreakAfterJavaFieldAnnotations</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">BreakStringLiterals</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">ColumnLimit</span><span class="p">:</span> <span class="mi">80</span>
<span class="nl">CommentPragmas</span><span class="p">:</span> <span class="s">&#34;^ NOLINT:&#34;</span>
<span class="nl">CompactNamespaces</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">ConstructorInitializerAllOnOneLineOrOnePerLine</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">ConstructorInitializerIndentWidth</span><span class="p">:</span> <span class="mi">4</span>
<span class="nl">ContinuationIndentWidth</span><span class="p">:</span> <span class="mi">4</span>
<span class="nl">Cpp11BracedListStyle</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">DeriveLineEnding</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">DerivePointerAlignment</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">DisableFormat</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">ExperimentalAutoDetectBinPacking</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">FixNamespaceComments</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">ForEachMacros</span><span class="p">:</span>
  <span class="o">-</span> <span class="n">foreach</span>
  <span class="o">-</span> <span class="n">Q_FOREACH</span>
  <span class="o">-</span> <span class="n">BOOST_FOREACH</span>
<span class="nl">IncludeBlocks</span><span class="p">:</span> <span class="n">Regroup</span>
<span class="nl">IncludeCategories</span><span class="p">:</span>
  <span class="o">-</span> <span class="nl">Regex</span><span class="p">:</span> <span class="err">&#39;</span><span class="o">^&lt;</span><span class="n">ext</span><span class="o">/</span><span class="p">.</span><span class="o">*</span><span class="err">\</span><span class="p">.</span><span class="n">h</span><span class="o">&gt;</span><span class="err">&#39;</span>
    <span class="nl">Priority</span><span class="p">:</span> <span class="mi">2</span>
    <span class="nl">SortPriority</span><span class="p">:</span> <span class="mi">0</span>
  <span class="o">-</span> <span class="nl">Regex</span><span class="p">:</span> <span class="err">&#39;</span><span class="o">^&lt;</span><span class="p">.</span><span class="o">*</span><span class="err">\</span><span class="p">.</span><span class="n">h</span><span class="o">&gt;</span><span class="err">&#39;</span>
    <span class="nl">Priority</span><span class="p">:</span> <span class="mi">1</span>
    <span class="nl">SortPriority</span><span class="p">:</span> <span class="mi">0</span>
  <span class="o">-</span> <span class="nl">Regex</span><span class="p">:</span> <span class="s">&#34;^&lt;.*&#34;</span>
    <span class="nl">Priority</span><span class="p">:</span> <span class="mi">2</span>
    <span class="nl">SortPriority</span><span class="p">:</span> <span class="mi">0</span>
  <span class="o">-</span> <span class="nl">Regex</span><span class="p">:</span> <span class="s">&#34;.*&#34;</span>
    <span class="nl">Priority</span><span class="p">:</span> <span class="mi">3</span>
    <span class="nl">SortPriority</span><span class="p">:</span> <span class="mi">0</span>
<span class="nl">IncludeIsMainRegex</span><span class="p">:</span> <span class="s">&#34;([-_](test|unittest))?$&#34;</span>
<span class="nl">IncludeIsMainSourceRegex</span><span class="p">:</span> <span class="s">&#34;&#34;</span>
<span class="nl">IndentCaseLabels</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">IndentGotoLabels</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">IndentPPDirectives</span><span class="p">:</span> <span class="n">None</span>
<span class="nl">IndentWidth</span><span class="p">:</span> <span class="mi">4</span>
<span class="nl">IndentWrappedFunctionNames</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">JavaScriptQuotes</span><span class="p">:</span> <span class="n">Leave</span>
<span class="nl">JavaScriptWrapImports</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">KeepEmptyLinesAtTheStartOfBlocks</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">MacroBlockBegin</span><span class="p">:</span> <span class="s">&#34;&#34;</span>
<span class="nl">MacroBlockEnd</span><span class="p">:</span> <span class="s">&#34;&#34;</span>
<span class="nl">MaxEmptyLinesToKeep</span><span class="p">:</span> <span class="mi">1</span>
<span class="nl">NamespaceIndentation</span><span class="p">:</span> <span class="n">None</span>
<span class="nl">ObjCBinPackProtocolList</span><span class="p">:</span> <span class="n">Never</span>
<span class="nl">ObjCBlockIndentWidth</span><span class="p">:</span> <span class="mi">2</span>
<span class="nl">ObjCSpaceAfterProperty</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">ObjCSpaceBeforeProtocolList</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">PenaltyBreakAssignment</span><span class="p">:</span> <span class="mi">2</span>
<span class="nl">PenaltyBreakBeforeFirstCallParameter</span><span class="p">:</span> <span class="mi">1</span>
<span class="nl">PenaltyBreakComment</span><span class="p">:</span> <span class="mi">300</span>
<span class="nl">PenaltyBreakFirstLessLess</span><span class="p">:</span> <span class="mi">120</span>
<span class="nl">PenaltyBreakString</span><span class="p">:</span> <span class="mi">1000</span>
<span class="nl">PenaltyBreakTemplateDeclaration</span><span class="p">:</span> <span class="mi">10</span>
<span class="nl">PenaltyExcessCharacter</span><span class="p">:</span> <span class="mi">1000000</span>
<span class="nl">PenaltyReturnTypeOnItsOwnLine</span><span class="p">:</span> <span class="mi">200</span>
<span class="nl">PointerAlignment</span><span class="p">:</span> <span class="n">Right</span>
<span class="nl">RawStringFormats</span><span class="p">:</span>
  <span class="o">-</span> <span class="nl">Language</span><span class="p">:</span> <span class="n">Cpp</span>
    <span class="nl">Delimiters</span><span class="p">:</span>
      <span class="o">-</span> <span class="n">cc</span>
      <span class="o">-</span> <span class="n">CC</span>
      <span class="o">-</span> <span class="n">cpp</span>
      <span class="o">-</span> <span class="n">Cpp</span>
      <span class="o">-</span> <span class="n">CPP</span>
      <span class="o">-</span> <span class="s">&#34;c++&#34;</span>
      <span class="o">-</span> <span class="s">&#34;C++&#34;</span>
    <span class="nl">CanonicalDelimiter</span><span class="p">:</span> <span class="s">&#34;&#34;</span>
    <span class="nl">BasedOnStyle</span><span class="p">:</span> <span class="n">google</span>
  <span class="o">-</span> <span class="nl">Language</span><span class="p">:</span> <span class="n">TextProto</span>
    <span class="nl">Delimiters</span><span class="p">:</span>
      <span class="o">-</span> <span class="n">pb</span>
      <span class="o">-</span> <span class="n">PB</span>
      <span class="o">-</span> <span class="n">proto</span>
      <span class="o">-</span> <span class="n">PROTO</span>
    <span class="nl">EnclosingFunctions</span><span class="p">:</span>
      <span class="o">-</span> <span class="n">EqualsProto</span>
      <span class="o">-</span> <span class="n">EquivToProto</span>
      <span class="o">-</span> <span class="n">PARSE_PARTIAL_TEXT_PROTO</span>
      <span class="o">-</span> <span class="n">PARSE_TEST_PROTO</span>
      <span class="o">-</span> <span class="n">PARSE_TEXT_PROTO</span>
      <span class="o">-</span> <span class="n">ParseTextOrDie</span>
      <span class="o">-</span> <span class="n">ParseTextProtoOrDie</span>
    <span class="nl">CanonicalDelimiter</span><span class="p">:</span> <span class="s">&#34;&#34;</span>
    <span class="nl">BasedOnStyle</span><span class="p">:</span> <span class="n">google</span>
<span class="nl">ReflowComments</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">SortIncludes</span><span class="p">:</span> <span class="n">CaseInsensitive</span>
<span class="nl">SortUsingDeclarations</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpaceAfterCStyleCast</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpaceAfterLogicalNot</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpaceAfterTemplateKeyword</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">SpaceBeforeAssignmentOperators</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">SpaceBeforeCpp11BracedList</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpaceBeforeCtorInitializerColon</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">SpaceBeforeInheritanceColon</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">SpaceBeforeParens</span><span class="p">:</span> <span class="n">ControlStatements</span>
<span class="nl">SpaceBeforeRangeBasedForLoopColon</span><span class="p">:</span> <span class="nb">true</span>
<span class="nl">SpaceInEmptyBlock</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpaceInEmptyParentheses</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpacesBeforeTrailingComments</span><span class="p">:</span> <span class="mi">1</span>
<span class="nl">SpacesInAngles</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpacesInConditionalStatement</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpacesInContainerLiterals</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpacesInCStyleCastParentheses</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpacesInParentheses</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpacesInSquareBrackets</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">SpaceBeforeSquareBrackets</span><span class="p">:</span> <span class="nb">false</span>
<span class="nl">Standard</span><span class="p">:</span> <span class="n">Auto</span>
<span class="nl">StatementMacros</span><span class="p">:</span>
  <span class="o">-</span> <span class="n">Q_UNUSED</span>
  <span class="o">-</span> <span class="n">QT_REQUIRE_VERSION</span>
<span class="nl">TabWidth</span><span class="p">:</span> <span class="mi">4</span>
</code></pre></div><h2 id="编译工具链设置">编译工具链设置</h2>
<h3 id="编译工具链的添加与解释">编译工具链的添加与解释</h3>
<p>这个配置是进行C++开发的关键，因为这个编译工具链就意味着C++的编译环境。</p>
<p>按下图点开对应的信息，如果你任何编译工具链都没有添加，由于新版本的CLion它会自带一个mingw的编译套件，所以默认会有一个CLion自带的mingw编译工具链，如下图所示我的编译工具链稍微有点丰富，有 msvc、g++、clang++、mingw，作为一个刚刚入门学编程的新手，我建议编译工具链这一块暂时就没必要了解了，但在CLion中编译的具体配置流程我认为还是有必要讲清楚。<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/b781629c17a14e23959cce83e5f07823.png"
        data-srcset="https://img-blog.csdnimg.cn/b781629c17a14e23959cce83e5f07823.png, https://img-blog.csdnimg.cn/b781629c17a14e23959cce83e5f07823.png 1.5x, https://img-blog.csdnimg.cn/b781629c17a14e23959cce83e5f07823.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/b781629c17a14e23959cce83e5f07823.png"
        title="bianyi" /></p>
<p>CLion中添加编译工具链非常简单，你本机把对应工具链的路径加入到了环境变量，那么在你点击 <code>+</code> 对应编译链类型后，会自动扫描到，如果实在没有扫描到，那么也可以自己填入对应的路径，整个编译链包括：</p>
<ol>
<li>cmake，用于跨平台以及简化底层编译脚本的工具。</li>
<li>cmake生成更底层的编译命令(对应上述的Build Tool)，比如gmake也就是解析.makefile文件进行命令执行，比如 ninja 解析 .ninja文件进行命令执行（编译速度比makefile更快，亲身体验）。</li>
<li>C语言的编译器(clang/gcc/cl等等)。</li>
<li>C++的编译器(clang++/g++/cl等等)。</li>
</ol>
<p>如果是mingw，那么上述的一套都是包含的，只需要把 Toolset 这个选项选择为mingw对应的目录即可，选择好后，CLion会自动识别上述四件套的位置。</p>
<p>接下来简单介绍如何添加一些工具链：</p>
<ul>
<li>安装msvc编译工具链：直接到官网下载VS2022，然后安装对应C++环境，打开CLion后添加msvc环境时就会自动识别。官网：<a href="https://visualstudio.microsoft.com/zh-hans/vs/" target="_blank" rel="noopener noreffer">https://visualstudio.microsoft.com/zh-hans/vs/</a></li>
</ul>
<p>其实对于我们C++程序员而言，最需要的就是一个Linux环境，因为很多底层的系统调用是不在C++标准之内的，C++想要做到跨平台很难，所以我们需要把开发环境切换到Linux系统，正好windows提供了Linux子系统，也就是wsl，完美的解决了这个问题，不要考虑日常的使用和开发环境我们到底选哪个了，我全都要！</p>
<p>而CLion对wsl的适配程度和正常的本机开发几乎没有任何区别，我们只需要现在Windows上安装wsl2后，CLion便可以自动识别你本机的wsl环境了，但是你有了wsl，并不意味着你有了对应的编译链，之前说了，编译链是包括四个东西的，你需要一一手动再wsl上先安装好，CLion会自动识别到的，如果识别不到，由于是通过 <code>apt install</code> 命令安装的，大家应该都清楚在具体那个目录下，实在不清楚可以使用 <code>which</code> 命令。</p>
<ul>
<li>安装wsl2：其实wsl2的安装已经被简化到了极致，在powershell中 <code>wsl --install</code> 即可。
具体的官方文档如下 <a href="https://learn.microsoft.com/zh-cn/windows/wsl/install" target="_blank" rel="noopener noreffer">https://learn.microsoft.com/zh-cn/windows/wsl/install</a> ，一篇非常简练的博客教程：<a href="https://zhuanlan.zhihu.com/p/438255467" target="_blank" rel="noopener noreffer">https://zhuanlan.zhihu.com/p/438255467</a>，如果安装遇到问题（大概率网络问题），请自行谷歌或百度或bing或chatgpt。</li>
<li>如果需要使用CLion进行Qt开发，可以查看视频讲解：<a href="https://www.bilibili.com/video/BV18q4y1i7kV/" target="_blank" rel="noopener noreffer">https://www.bilibili.com/video/BV18q4y1i7kV/</a>  ，对应的配置信息：<a href="https://gitee.com/yuexingqin/template_qtclion" target="_blank" rel="noopener noreffer">https://gitee.com/yuexingqin/template_qtclion</a></li>
<li>如果需要使用CLion进行STM32开发，那么可以查看稚晖君在知乎写的博客教程：<a href="https://zhuanlan.zhihu.com/p/145801160" target="_blank" rel="noopener noreffer">https://zhuanlan.zhihu.com/p/145801160</a></li>
</ul>
<h3 id="cmake配置项的添加与解释">cmake配置项的添加与解释</h3>
<p>解释完上述编译链后，我们发现CLion中有个很明显的 <code>default</code> 字眼，这个有什么用呢？</p>
<p>如果排在第一个的编译链，会被设置为默认编译链，如果想要其他的编译链为默认，点击上移即可。</p>
<p>至于具体的作用，别急，先等我讲完CLion中cmake配置项的处理。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/2cc29f67403e4c7ba5c46bacee36e065.png"
        data-srcset="https://img-blog.csdnimg.cn/2cc29f67403e4c7ba5c46bacee36e065.png, https://img-blog.csdnimg.cn/2cc29f67403e4c7ba5c46bacee36e065.png 1.5x, https://img-blog.csdnimg.cn/2cc29f67403e4c7ba5c46bacee36e065.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/2cc29f67403e4c7ba5c46bacee36e065.png"
        title="clion1" /></p>
<p>如上图所示，第二个 <code>CMake</code> 选项就是我们现在要讲的东西，而这两个正好也是整个开发环境中最重要的东西，第一个编译工具链决定了CLion中已经识别了本机有哪些编译环境，而第二个 <code>CMake</code> 选项，则是用于配置 cmake 基于哪些配置项生成。</p>
<p>所以我们现在应该了解了CLion是如何去编译项目生成可执行文件的了。</p>
<ol>
<li>通过cmake配置选项运行整个项目的CMakeList.txt</li>
<li>生成makefile或其他底层脚本后再通过对应的工具去执行这个脚本</li>
<li>运行编译好的程序</li>
</ol>
<p>而我们现在讲的就是添加cmake配置选项，如果你手动敲cmake命令的话，那样对应的就是命令行参数了。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/445c81d7247549c9af62193885af47d0.png"
        data-srcset="https://img-blog.csdnimg.cn/445c81d7247549c9af62193885af47d0.png, https://img-blog.csdnimg.cn/445c81d7247549c9af62193885af47d0.png 1.5x, https://img-blog.csdnimg.cn/445c81d7247549c9af62193885af47d0.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/445c81d7247549c9af62193885af47d0.png"
        title="clion3" /></p>
<p>上述图片中已经解释了一些配置的作用。这些配置项一般是不常改动，使用默认值就行，比如 <code>Build options</code> 是执行最后的脚本所用的参数，默认为 <code>-j 12</code>，比如如果是makefile，那么就是 <code>make -j12</code>。</p>
<p>下面是大家可能需要进行一些配置的选项：</p>
<ol>
<li>Build type：这是程序最终编译的类型，意味着编译器该以何种程度对源代码进行优化，比如Debug版本一般再gcc中对应o2的优化，release版本对应o3的优化，两者一般存在10倍左右的性能差距。</li>
<li>Toolchain：这是前面所说的编译工具链，一般来说，想要切换编译器，你切换这个选项就行了，默认使用default工具链。</li>
<li>Generator：这是前面所说的工具链中的较为底层的脚本的运行工具，可以是makefile或者ninja，不选的话也是默认工具链里的那个。</li>
<li>CMake options：这个是cmake运行时可以加入的命令行参数，比如我们可以-D来定义对应的变量控制对应的cmake行为，甚至于前面的Build type我们完全可以不写（当然这是CLion，这个空必须得被填充），然后使用-DCMAKE_BUILD_TYPE=Release，这个变量可以决定最终cmake生成的执行脚本是按照release的标准去运行的，又比如-DBUILD_SHARED_LIBS=ON，那么最终是会生成动态库而不是静态库，我上图中的 -DENABLE_TEST=ON 是内部的cmake有定义一个变量默认为OFF值，如果为ON时会加入测试代码为子项目。</li>
</ol>
<p>现在cmake在CLion中的配置项已经讲完了，简单实践一下来体验之前讲的CLion到整个运行的流程，我这里就直接配图了：</p>
<ol>
<li>通过cmake配置选项运行整个项目的CMakeList.txt。
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/a73b91c93eaf148175b9881385a080dc.png"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/a73b91c93eaf148175b9881385a080dc.png, https://img-blog.csdnimg.cn/img_convert/a73b91c93eaf148175b9881385a080dc.png 1.5x, https://img-blog.csdnimg.cn/img_convert/a73b91c93eaf148175b9881385a080dc.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/a73b91c93eaf148175b9881385a080dc.png"
        title="clion4" /></li>
<li>生成makefile或其他底层脚本后再通过对应的工具去执行这个脚本。
我们先看一眼上一步cmake生成的文件（放出了两个不同的配置项产生的脚本，第一个使用的Generator为ninja，第二个使用的为gmake）：
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/a037638634fa4643908dddfb3741925f.png"
        data-srcset="https://img-blog.csdnimg.cn/a037638634fa4643908dddfb3741925f.png, https://img-blog.csdnimg.cn/a037638634fa4643908dddfb3741925f.png 1.5x, https://img-blog.csdnimg.cn/a037638634fa4643908dddfb3741925f.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/a037638634fa4643908dddfb3741925f.png"
        title="clion5" />
如果想要继续执行这个脚本，应该在CLion中执行对应的源代码，CLion会自动识别入口点函数，然后给出可执行的按钮，如图：
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/c7c4a58136fb475cb616b66a561328f3.png"
        data-srcset="https://img-blog.csdnimg.cn/c7c4a58136fb475cb616b66a561328f3.png, https://img-blog.csdnimg.cn/c7c4a58136fb475cb616b66a561328f3.png 1.5x, https://img-blog.csdnimg.cn/c7c4a58136fb475cb616b66a561328f3.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/c7c4a58136fb475cb616b66a561328f3.png"
        title="clion6" />
点击执行后，不仅会直接对应的 makefile 或 build.ninja 还会顺便把这个程序运行到CLion内置的终端环境中。</li>
<li>运行编译好的程序：这一步已经在第二步一并执行了。</li>
</ol>
<p>理解了这三步以及cmake的配置之后，我相信如果突然间CLion不出现执行程序的按钮，或者一个外部的项目我们无法跑起来，那么我们肯定是会有对应的排查思路了。比如没有执行程序的按钮，那可能对应的cmake配置项你还没设置好，如果外部项目跑不起来，你可以把那四个编译工具链中的某个换其他的环境试试？</p>
<h2 id="cmake的使用与实战">cmake的使用与实战</h2>
<p>经过上述文字和图片讲解，我们很自然的想到，整个CLion运行C++代码其实就是在运行cmake和makefile(或build.ninja)，第二个过程我们参与不了，但是第一个cmake的编写过程我们却需要一直接触。</p>
<p>下面用CLion新建项目自动生成的cmake模板来简单对cmake语法热热身。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">cmake_minimum_required</span><span class="p">(</span><span class="s">VERSION</span> <span class="s">3.22</span><span class="p">)</span><span class="err">
</span><span class="err"></span><span class="nb">project</span><span class="p">(</span><span class="s">untitled</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">set</span><span class="p">(</span><span class="s">CMAKE_CXX_STANDARD</span> <span class="s">17</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">add_executable</span><span class="p">(</span><span class="s">untitled</span> <span class="s">main.cpp</span><span class="p">)</span><span class="err">
</span></code></pre></div><ul>
<li>
<p>cmake_minimum_required命令：规定了编译本项目的cmake工具至少需要3.22版本。</p>
</li>
<li>
<p>project命令：规定了本项目的项目名称，同时也根据这个传入的值生成了一堆变量，常用的如下：</p>
<ol>
<li>PROJECT_NAME：项目名称</li>
<li>PROJECT_BINARY_DIR：项目的二进制文件目录，即编译后的可执行文件和库文件的输出目录</li>
<li>PROJECT_SOURCE_DIR：项目的源文件目录，即包含CMakeLists.txt文件的目录</li>
</ol>
<p>举个简单例子说明上述变量的作用：
比如一个测试的子项目中的CMakeList.txt，可能需要写下面的语句（先不管file命令），由于是作为直接的子项目，那么里面肯定不会存在project语句，所以PROJECT_SOURCE_DIR变量表示的仍然是整个项目的根目录，直接通过 <code>${}</code> 的形式来使用它即可，这样就不需要关心相对或绝对路径了。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">file</span><span class="p">(</span><span class="s">GLOB</span> <span class="s">SONIC_TEST_FILES</span>
     <span class="s2">&#34;${PROJECT_SOURCE_DIR}/tests/*.h&#34;</span>
     <span class="s2">&#34;${PROJECT_SOURCE_DIR}/tests/*.cpp&#34;</span>
<span class="p">)</span><span class="err">
</span></code></pre></div></li>
<li>
<p>set命令：设置对应变量为对应的值，该变量存在，则修改该变量的值，如果不存在则会创建并初始化为对应的值，这里对set的使用是设置了 CMAKE_CXX_STANDARD 变量为17，这个变量可以控制最终编译采用的C++版本，这里是使用C++17。</p>
</li>
<li>
<p>add_executable命令：这是用于生成可执行程序的命令，第一个参数为该执行程序最终编译后生成的文件名，后面跟着的都是需要编译的源代码。</p>
</li>
</ul>
<p>对于新手而言，其实压根不需要自己手写cmake，因为CLion会在你新建源文件的时候把相应源文件添加到add_excutable命令的后面。</p>
<h3 id="常用的cmake变量入门">常用的cmake变量（入门）</h3>
<p>下面只列出了部分变量的作用，更多的变量请查看文档：<a href="https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html" target="_blank" rel="noopener noreffer">https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html</a></p>
<ul>
<li>PROJECT_NAME：项目名称</li>
<li>PROJECT_BINARY_DIR：项目的二进制文件目录，即编译后的可执行文件和库文件的输出目录</li>
<li>PROJECT_SOURCE_DIR：项目的源文件目录，即包含CMakeLists.txt文件的目录</li>
<li>CMAKE_BINARY_DIR：当前CMake运行的二进制文件目录，通常和PROJECT_BINARY_DIR是同一个目录</li>
<li>CMAKE_SOURCE_DIR：当前CMake运行的源文件目录，通常和PROJECT_SOURCE_DIR是同一个目录</li>
<li>CMAKE_C_STANDARD：指定C语言的标准版本</li>
<li>CMAKE_CXX_STANDARD：指定C++语言的标准版本</li>
<li>CMAKE_CXX_FLAGS：指定编译C++代码时使用的编译选项</li>
<li>CMAKE_C_FLAGS：指定编译C代码时使用的编译选项</li>
<li>CMAKE_EXE_LINKER_FLAGS：指定链接可执行文件时使用的链接选项</li>
<li>CMAKE_SYSTEM_NAME：指定当前操作系统名称（如Windows、Linux等）</li>
<li>CMAKE_SYSTEM_PROCESSOR：指定当前处理器的类型（如x86、x86_64等）</li>
<li>CMAKE_CXX_COMPILER_ID：指定了当前使用的C++编译器，同理可得C的编译器对应的名字。</li>
</ul>
<p>对这些变量做一个简单的实践：</p>
<ol>
<li>
<p>通过message打印出PROJECT_BINARY_DIR、PROJECT_SOURCE_DIR、CMAKE_BINARY_DIR、CMAKE_SOURCE_DIR来加以验证。
目录结构：</p>
<pre><code>.
├── CMakeLists.txt
├── main.cpp
└── sub
    └── CMakeLists.txt
</code></pre><p>cmake:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="err">main:
</span><span class="err"></span><span class="nb">cmake_minimum_required</span><span class="p">(</span><span class="s">VERSION</span> <span class="s">3.14</span><span class="p">)</span><span class="err">
</span><span class="err"></span><span class="nb">project</span><span class="p">(</span><span class="s">main</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">add_subdirectory</span><span class="p">(</span><span class="s">sub</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">message</span><span class="p">(</span><span class="s">STATUS</span> <span class="s2">&#34;main:${PROJECT_NAME}\n  pro-src:${PROJECT_SOURCE_DIR}\n pro-bin:${PROJECT_BINARY_DIR}\n cmake-src:${CMAKE_SOURCE_DIR}\n cmake-bin:${CMAKE_BINARY_DIR}&#34;</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err">sub:
</span><span class="err"></span><span class="nb">project</span><span class="p">(</span><span class="s">sub</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">message</span><span class="p">(</span><span class="s">STATUS</span> <span class="s2">&#34;sub:${PROJECT_NAME}\n  pro-src:${PROJECT_SOURCE_DIR}\n pro-bin:${PROJECT_BINARY_DIR}\n cmake-src:${CMAKE_SOURCE_DIR}\n cmake-bin:${CMAKE_BINARY_DIR}&#34;</span><span class="p">)</span><span class="err">
</span></code></pre></div><p>打印信息如下：我们发现CMake对应的变量没有变化，而Prject有了变量，因为我们在sub也使用了project命令。
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/a5b9c330ca044392b2e181c48ce773fd.png"
        data-srcset="https://img-blog.csdnimg.cn/a5b9c330ca044392b2e181c48ce773fd.png, https://img-blog.csdnimg.cn/a5b9c330ca044392b2e181c48ce773fd.png 1.5x, https://img-blog.csdnimg.cn/a5b9c330ca044392b2e181c48ce773fd.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/a5b9c330ca044392b2e181c48ce773fd.png"
        title="clion7" /></p>
</li>
<li>
<p>通过变量检测环境执行不同的cmake代码：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="c">#判断当前的操作系统
</span><span class="c"></span><span class="nb">if</span> <span class="p">(</span><span class="s">CMAKE_SYSTEM_NAME</span> <span class="s">MATCHES</span> <span class="s2">&#34;Linux&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>    <span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">my-logger</span> <span class="s">PUBLIC</span> <span class="s">fmt-header-only</span> <span class="s">pthread</span><span class="p">)</span><span class="err">
</span><span class="err"></span>    <span class="nb">message</span><span class="p">(</span><span class="s">STATUS</span> <span class="s2">&#34;Now is Linux&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span><span class="nb">elseif</span> <span class="p">(</span><span class="s">CMAKE_SYSTEM_NAME</span> <span class="s">MATCHES</span> <span class="s2">&#34;Windows&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>    <span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">my-logger</span> <span class="s">PUBLIC</span> <span class="s">fmt-header-only</span> <span class="s">ws2_32</span><span class="p">)</span><span class="err">
</span><span class="err"></span>    <span class="nb">message</span><span class="p">(</span><span class="s">STATUS</span> <span class="s2">&#34;Now is windows&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span><span class="nb">endif</span> <span class="p">()</span><span class="err">
</span><span class="err"></span><span class="c">#判断当前使用的编译器
</span><span class="c"></span><span class="nb">if</span> <span class="p">(</span><span class="s">CMAKE_CXX_COMPILER_ID</span> <span class="s">STREQUAL</span> <span class="s2">&#34;GNU&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for GCC
</span><span class="c"></span><span class="nb">elseif</span> <span class="p">(</span><span class="s">CMAKE_CXX_COMPILER_ID</span> <span class="s">STREQUAL</span> <span class="s2">&#34;Intel&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for Intel C++
</span><span class="c"></span><span class="nb">elseif</span> <span class="p">(</span><span class="s">CMAKE_CXX_COMPILER_ID</span> <span class="s">STREQUAL</span> <span class="s2">&#34;Microsoft&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for Microsoft Visual C++
</span><span class="c"></span><span class="nb">elseif</span> <span class="p">(</span><span class="s">CMAKE_CXX_COMPILER_ID</span> <span class="s">STREQUAL</span> <span class="s2">&#34;Clang&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for Clang
</span><span class="c"></span><span class="nb">endif</span><span class="p">()</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="c">#判断当前的系统架构
</span><span class="c"></span><span class="nb">if</span> <span class="p">(</span><span class="s">CMAKE_SYSTEM_PROCESSOR</span> <span class="s">MATCHES</span> <span class="s2">&#34;i.86|x86|x86_64|AMD64&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for x86 architecture
</span><span class="c"></span><span class="nb">elseif</span> <span class="p">(</span><span class="s">CMAKE_SYSTEM_PROCESSOR</span> <span class="s">MATCHES</span> <span class="s2">&#34;^(arm|aarch64)&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for ARM architecture
</span><span class="c"></span><span class="nb">elseif</span> <span class="p">(</span><span class="s">CMAKE_SYSTEM_PROCESSOR</span> <span class="s">MATCHES</span> <span class="s2">&#34;^(mips|mipsel|mips64)&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for MIPS architecture
</span><span class="c"></span><span class="nb">elseif</span> <span class="p">(</span><span class="s">CMAKE_SYSTEM_PROCESSOR</span> <span class="s">MATCHES</span> <span class="s2">&#34;^(powerpc|ppc64)&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>  <span class="c"># Do something for PowerPC architecture
</span><span class="c"></span><span class="nb">endif</span><span class="p">()</span><span class="err">
</span></code></pre></div></li>
<li>
<p>通过调整链接时的flag防止动态链接，因为如果你是使用Windows平台下的编译工具链，CLion有些时候最终链接并不是采用静态链接，导致你最终生成的可执行程序没法直接执行，这个时候你就需要使用下面的命令来强制静态链接了：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">set</span><span class="p">(</span><span class="s">CMAKE_EXE_LINKER_FLAGS</span> <span class="s2">&#34;-static&#34;</span><span class="p">)</span><span class="err">
</span></code></pre></div></li>
</ol>
<h3 id="常用的cmake命令入门">常用的cmake命令（入门）</h3>
<p>下列只列出了部分命令，如果你以后有需要用到的其他命令，请前往官网进行查询：<a href="https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html" target="_blank" rel="noopener noreffer">https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html</a></p>
<p>我个人较为常用的命令：</p>
<ol>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/project.html" target="_blank" rel="noopener noreffer">project</a>：用于定义项目名称、版本号和语言。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/add_executable.html" target="_blank" rel="noopener noreffer">add_executable</a>：用于添加可执行文件。第一个参数很重要，被称为target，可以作为target_xxx命令的接收对象。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/add_library.html" target="_blank" rel="noopener noreffer">add_library</a>：用于添加库文件，可以创建静态库或动态库。第一个参数很重要，被称为target，可以作为target_xxx命令的接收对象。简单使用如下</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">add_library</span><span class="p">(</span><span class="s">test_lib</span> <span class="s">a.cc</span> <span class="s">b.cc</span><span class="p">)</span> <span class="c">#默认生成静态库
</span><span class="c"></span><span class="nb">add_library</span><span class="p">(</span><span class="s">test_lib</span> <span class="s">SHARED</span> <span class="s">a.cc</span> <span class="s">b.cc</span><span class="p">)</span> <span class="c">#默认生成静态库
</span></code></pre></div></li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/add_definitions.html" target="_blank" rel="noopener noreffer">add_definitions</a>：用于添加宏定义，注意该命令没有执行顺序的问题，只要改项目中用了该命令定义宏，那么所有的源代码都会被定义这个宏 <code>add_definitions(-DFOO -DBAR ...)</code> 。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/add_subdirectory.html" target="_blank" rel="noopener noreffer">add_subdirectory</a>：用于添加子项目目录，如果有该条语句，就先会跑去执行子项目的cmake代码，这样会导致一些需要执行后立马生效的语句作用不到，比如include_directories和link_directories如果执行在这条语句后面，则他们添加的目录在子项目中无法生效。有些命令如target_include_directories和target_link_directories是根据目标target是否被链接使用来生效的，所以这些命令的作用范围与执行顺序无关，且恰好同一个cmake项目中产生的库文件是可以直接通过名称链接的，无论链接对象是在子目录还是父目录</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/target_link_libraries.html" target="_blank" rel="noopener noreffer">target_link_libraries</a>：用于将可执行文件或库文件链接到库文件或可执行文件。身为target_xxx的一员，很明显第二个参数也可以进行权限控制。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/include_directories.html" target="_blank" rel="noopener noreffer">include_directories</a>：用于指定头文件搜索路径，优点是简单直接，缺点是无法进行权限控制，一旦被执行后，后续的所有代码都能搜索到对应的文件路径。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/target_include_directories.html" target="_blank" rel="noopener noreffer">target_include_directories</a>：指定头文件搜索路径，并将搜索路径关联到一个target上，这里的target一般是指生成可执行程序命令里的target或者生成库文件的target，与上一个命令的不同点在于可以设置导出权限，比如现在我写了一个项目，这个项目引入了其他库，但是我不想让其他库的符号暴露出去（毕竟使用这个项目的人只关注这个项目的接口，不需要关注其他依赖的接口）可以通过PRIVATE将头文件搜索目录设置不导出的权限。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/link_directories.html" target="_blank" rel="noopener noreffer">link_directories</a>：与前面的include_directories命令类似，添加的是库的搜索路径。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/target_link_directories.html" target="_blank" rel="noopener noreffer">target_link_directories</a>：和前面的include版本一样的，只是改成了库路径。</p>
</li>
<li>
<p>if\elseif\endif ，在编程语言立马已经用烂了，现在主要是了解 if(condition) 中的条件到底如何判断的，以及内部都支持哪些操作，比如大于等于啥的，这方面直接看官方文档吧，非常好懂：<a href="https://cmake.org/cmake/help/latest/command/if.html" target="_blank" rel="noopener noreffer">https://cmake.org/cmake/help/latest/command/if.html</a></p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/aux_source_directory.html" target="_blank" rel="noopener noreffer">aux_source_directory</a>：这个指令简单实用，第一个参数传递一个文件目录，它会扫描这里面所有的源文件放到第二个参数定义的变量名中。注意第一个参数只能是文件夹。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">aux_source_directory</span><span class="p">(</span><span class="o">${</span><span class="nv">PROJECT_SOURCE_DIR</span><span class="o">}</span> <span class="s">SRC</span><span class="p">)</span><span class="err">
</span></code></pre></div></li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/file.html" target="_blank" rel="noopener noreffer">file</a>：可以说是上面那个命令的增强版本，但如果熟悉这个命令的朋友肯定很快站出来反对，因为这个命令实在是太强大了，你如果翻一翻这个官方文档就会发现它具备几乎文件系统的所有功能，什么读写文件啊，什么从网上下载文件，本地上传文件之类的它都有，计算文件的相对路径，路径转化等等。但我们平时用到的最多的命令还是用来获取文件到变量里。比如file(GLOB FILES &ldquo;文件路径表示1&rdquo; &ldquo;文件路径表示2&rdquo; &hellip;) GLOB会产生一个由所有匹配globbing表达式的文件组成的列表，并将其保存到第二个参数定义的变量中。Globbing 表达式与正则表达式类似，但更简单，比如如果要实现前一个命令的功能可以这么写：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">file</span><span class="p">(</span><span class="s">GLOB</span> <span class="s">SRC</span> <span class="s2">&#34;${PROJECT_SOURCE_DIR}/*.cc&#34;</span><span class="p">)</span><span class="err">
</span></code></pre></div><p>如果GLOB 换成GLOB_RECURSE ，那么上述命令将递归的搜寻其子目录的所有符合条件的文件，而不仅仅是一个层级。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/execute_process.html" target="_blank" rel="noopener noreffer">execute_process</a>：用于执行外部的命令，如下的示例代码是执行git clone命令，执行命令的工作目录在 <code>${CMAKE_BINARY_DIR}/deps/</code></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">execute_process</span><span class="p">(</span><span class="s">COMMAND</span> <span class="s">git</span> <span class="s">clone</span> <span class="s">https://github.com/&lt;username&gt;/&lt;repository&gt;.git</span>
                <span class="s">WORKING_DIRECTORY</span> <span class="o">${</span><span class="nv">CMAKE_BINARY_DIR</span><span class="o">}</span><span class="s">/deps/&lt;repository&gt;</span><span class="p">)</span><span class="err">
</span></code></pre></div></li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/message.html" target="_blank" rel="noopener noreffer">message</a>：打印出信息用于debug。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/option.html" target="_blank" rel="noopener noreffer">option</a>：用于快速设置定义变量并赋值为对应的bool值，常被用于判断某些操作是否执行。</p>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/find_package.html#id5" target="_blank" rel="noopener noreffer">find_package</a>：用于查找外界的package，其实就是查找外界对应的 <code>&lt;package&gt;Config.cmake</code> 和 <code>Find&lt;package&gt;.cmake</code> 文件，这些文件里有外界包对应的变量信息以及库和头文件的各种路径信息。我们需要注意一些有关 <code>find_package</code> 命令查找 Config.cmake 路径的变量：</p>
<ul>
<li><code>CMAKE_PREFIX_PATH</code> 变量是一个路径列表，CMake 会在这些路径中搜索包的 <code>Config.cmake</code> 文件。</li>
<li><code>&lt;Package&gt;_DIR</code> 变量是指向包的 <code>Config.cmake</code> 文件的路径。如果你手动设置了这个变量，那么 <code>find_package</code> 命令就可以找到包的信息。</li>
</ul>
<p>同时他的一些常用参数如下：</p>
<ul>
<li><code>CONFIG</code> ：显式指定find_package去查找 <code>&lt;package&gt;Config.cmake</code> 文件，一般只要你在变量里面指定了 <code>&lt;package&gt;Config.cmake</code>的路径，那么该参数填不填都没差别。我建议最好还是带上该参数比较好。</li>
<li><code>REQUIRED</code> ：该参数表示如果没找到，那么直接产生cmake错误，退出cmake执行过程，如果没有REQUIRED，则即使没找到也不会终止编译。</li>
<li><code>PATHS</code> ：这个参数的效果和前面的变量类似，也是指定查找的路径。</li>
<li><code>COMPONENTS</code> ：用于指定查找的模块，模块分离在不同的文件中，需要使用哪个就指定哪个模块。典型的就是使用Qt时的cmake代码，比如 <code>find_package(Qt5 COMPONENT Core Gui Widgets REQUIRED)</code> 。</li>
<li>VERSION：可能有很多个不同版本的包，则需要通过该参数来指定，如：<code>find_package(XXX VERSION 1.2.3)</code>。</li>
</ul>
</li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/include.html" target="_blank" rel="noopener noreffer">include</a>：从文件或模块加载并运行 CMake 代码。我用这个命令实际上只是为了使用 <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html#id1" target="_blank" rel="noopener noreffer">FetchContent</a><a href="https://cmake.org/cmake/help/latest/module/FetchContent.html#fetchcontent" target="_blank" rel="noopener noreffer">¶</a> 这个module的功能，该功能是从cmake3.11开始支持的，使用该module前需要通过include命令加载该模块，命令如下：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">include</span><span class="p">(</span><span class="s">FetchContent</span><span class="p">)</span><span class="err">
</span></code></pre></div></li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/module/FetchContent.html#id1" target="_blank" rel="noopener noreffer">FetchContent</a>：这是一个模块功能，它用来从代码仓库中拉取代码，例如我要把最近写的日志库引入到当前的项目中使用（注意这中间不会有任何代理，所以拉取GitHub的仓库可能失败）：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">include</span><span class="p">(</span><span class="s">FetchContent</span><span class="p">)</span><span class="c">#引入功能模块
</span><span class="c"></span><span class="err">
</span><span class="err"></span><span class="nb">FetchContent_Declare</span><span class="p">(</span>
        <span class="s">my-logger</span>  		 <span class="c">#项目名称
</span><span class="c"></span>        <span class="s">GIT_REPOSITORY</span> <span class="s">https://github.com/ACking-you/my-logger.git</span> <span class="c">#仓库地址
</span><span class="c"></span>        <span class="s">GIT_TAG</span>        <span class="s">v1.6.2</span>  <span class="c">#仓库的版本tag
</span><span class="c"></span>        <span class="s">GIT_SHALLOW</span> <span class="s">TRUE</span>    <span class="c">#是否只拉取最新的记录
</span><span class="c"></span><span class="p">)</span><span class="err">
</span><span class="err"></span><span class="nb">FetchContent_MakeAvailable</span><span class="p">(</span><span class="s">my-logger</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">add_excutable</span><span class="p">(</span><span class="s">main</span> <span class="o">${</span><span class="nv">SRC</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span><span class="c">#链接到程序进行使用
</span><span class="c"></span><span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">main</span> <span class="s">my-logger</span><span class="p">)</span><span class="err">
</span></code></pre></div><p>这样引入第三方库的好处显而易见，优点类似于包管理的效果了，但缺少了最关键的中心仓库来确保资源的有效和稳定。参考golang再做个proxy层级就好了。
同样可以拉取最新的googletest可以使用下列语句：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="nb">FetchContent_Declare</span><span class="p">(</span>
        <span class="s">googletest</span>
        <span class="s">GIT_REPOSITORY</span> <span class="s">https://github.com/google/googletest.git</span>
        <span class="s">GIT_TAG</span>        <span class="s">release-1.12.1</span>
        <span class="s">GIT_SHALLOW</span> <span class="s">TRUE</span>
<span class="p">)</span><span class="err">
</span><span class="err"></span><span class="c"># For Windows: Prevent overriding the parent project&#39;s compiler/linker settings
</span><span class="c"></span><span class="nb">set</span><span class="p">(</span><span class="s">gtest_force_shared_crt</span> <span class="s">ON</span> <span class="s">CACHE</span> <span class="s">BOOL</span> <span class="s2">&#34;&#34;</span> <span class="s">FORCE</span><span class="p">)</span><span class="err">
</span><span class="err"></span><span class="nb">FetchContent_MakeAvailable</span><span class="p">(</span><span class="s">googletest</span><span class="p">)</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">main</span> <span class="s">gtest_main</span><span class="p">)</span><span class="err">
</span></code></pre></div></li>
<li>
<p><a href="https://cmake.org/cmake/help/latest/command/function.html" target="_blank" rel="noopener noreffer">function/endfunction</a> ：在cmake中用于定义函数，复用cmake代码的命令。第一个参数为函数的名称，后面为参数的名称，使用参数和使用变量时一样的，但是如果参数是列表类型，则在传入的时候就会被展开，然后与函数参数依次对应，多余的参数被 <code>ARGN</code> 参数吸收。</p>
</li>
</ol>
<p>更多较为常用的命令：</p>
<ul>
<li><a href="https://cmake.org/cmake/help/latest/command/add_custom_command.html" target="_blank" rel="noopener noreffer">add_custom_command</a>：添加自定义规则命令，同样也是执行外界命令，但多了根据依赖和产物判断执行时机的作用。</li>
<li><a href="https://cmake.org/cmake/help/latest/command/install.html" target="_blank" rel="noopener noreffer">install</a>：添加install操作。</li>
<li><a href="https://cmake.org/cmake/help/latest/command/string.html" target="_blank" rel="noopener noreffer">string</a>：对string的所有操作，比如字符串替换啥的。</li>
<li><a href="https://cmake.org/cmake/help/latest/command/list.html" target="_blank" rel="noopener noreffer">list</a>：对list的所有操作，比如列表处理之类的。</li>
<li><a href="https://cmake.org/cmake/help/latest/command/foreach.html" target="_blank" rel="noopener noreffer">foreach</a>：cmake中的for循环。</li>
<li>&hellip;</li>
</ul>
<p>利用上述命令实现Qt开发中调用uic工具把 大量的 <code>.ui</code> 文件转化为 <code>.cpp</code> 和 <code>.h</code> 文件，并实现当ui文件更新时或 <code>.cpp/.h</code> 文件不存在时才创建对应的 <code>.cpp/.h</code> 文件。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cmake" data-lang="cmake"><span class="c">#函数功能实现
</span><span class="c"></span><span class="nb">function</span><span class="p">(</span><span class="s">get_ui_source</span><span class="p">)</span><span class="err">
</span><span class="err"></span>    <span class="nb">foreach</span> <span class="p">(</span><span class="s">item</span> <span class="o">${</span><span class="nv">ARGN</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">set</span><span class="p">(</span><span class="s">UIC_EXE_PATH</span> <span class="o">${</span><span class="nv">VCPKG_ROOT</span><span class="o">}</span><span class="s">/installed/x64-windows/tools/qt5/bin/uic.exe</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">get_filename_component</span><span class="p">(</span><span class="s">name</span> <span class="o">${</span><span class="nv">item</span><span class="o">}</span> <span class="s">NAME_WLE</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">string</span><span class="p">(</span><span class="s">PREPEND</span> <span class="s">name</span> <span class="s2">&#34;ui_&#34;</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">set</span><span class="p">(</span><span class="s">output_h</span> <span class="o">${</span><span class="nv">PROJECT_SOURCE_DIR</span><span class="o">}</span><span class="s">/ui_gen/</span><span class="o">${</span><span class="nv">name</span><span class="o">}</span><span class="s">.h</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">set</span><span class="p">(</span><span class="s">output_cpp</span> <span class="o">${</span><span class="nv">PROJECT_SOURCE_DIR</span><span class="o">}</span><span class="s">/ui_gen/</span><span class="o">${</span><span class="nv">name</span><span class="o">}</span><span class="s">.cpp</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">file</span><span class="p">(</span><span class="s">TIMESTAMP</span> <span class="o">${</span><span class="nv">item</span><span class="o">}</span> <span class="s">ui_time</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="c">#当.h文件已经存在时，仅当.ui文件被更新了才重新生成.h文件
</span><span class="c"></span>        <span class="nb">if</span> <span class="p">(</span><span class="s">EXISTS</span> <span class="o">${</span><span class="nv">output_h</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span>            <span class="nb">file</span><span class="p">(</span><span class="s">TIMESTAMP</span> <span class="o">${</span><span class="nv">output_h</span><span class="o">}</span> <span class="s">h_time</span><span class="p">)</span><span class="err">
</span><span class="err"></span>            <span class="nb">if</span> <span class="p">(</span><span class="s">ui_time</span> <span class="s">GREATER</span> <span class="s">h_time</span><span class="p">)</span><span class="err">
</span><span class="err"></span>                <span class="nb">execute_process</span><span class="p">(</span><span class="s">COMMAND</span> <span class="o">${</span><span class="nv">UIC_EXE_PATH</span><span class="o">}</span> <span class="o">${</span><span class="nv">item</span><span class="o">}</span> <span class="s">-o</span> <span class="o">${</span><span class="nv">output_h</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span>            <span class="nb">endif</span> <span class="p">()</span><span class="err">
</span><span class="err"></span>        <span class="nb">else</span> <span class="p">()</span><span class="err">
</span><span class="err"></span>            <span class="nb">execute_process</span><span class="p">(</span><span class="s">COMMAND</span> <span class="o">${</span><span class="nv">UIC_EXE_PATH</span><span class="o">}</span> <span class="o">${</span><span class="nv">item</span><span class="o">}</span> <span class="s">-o</span> <span class="o">${</span><span class="nv">output_h</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">endif</span> <span class="p">()</span><span class="err">
</span><span class="err"></span>        <span class="c">#当.cpp文件已经存在时，仅当.ui文件被更新了才重新生成.cpp文件
</span><span class="c"></span>        <span class="nb">if</span> <span class="p">(</span><span class="s">EXISTS</span> <span class="o">${</span><span class="nv">output_cpp</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span>            <span class="nb">file</span><span class="p">(</span><span class="s">TIMESTAMP</span> <span class="o">${</span><span class="nv">output_cpp</span><span class="o">}</span> <span class="s">cpp_time</span><span class="p">)</span><span class="err">
</span><span class="err"></span>            <span class="nb">if</span> <span class="p">(</span><span class="s">ui_time</span> <span class="s">GREATER</span> <span class="s">cpp_time</span><span class="p">)</span><span class="err">
</span><span class="err"></span>                <span class="nb">execute_process</span><span class="p">(</span><span class="s">COMMAND</span> <span class="o">${</span><span class="nv">UIC_EXE_PATH</span><span class="o">}</span> <span class="o">${</span><span class="nv">item</span><span class="o">}</span> <span class="s">-o</span> <span class="o">${</span><span class="nv">output_cpp</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span>            <span class="nb">endif</span> <span class="p">()</span><span class="err">
</span><span class="err"></span>        <span class="nb">else</span> <span class="p">()</span><span class="err">
</span><span class="err"></span>            <span class="nb">execute_process</span><span class="p">(</span><span class="s">COMMAND</span> <span class="o">${</span><span class="nv">UIC_EXE_PATH</span><span class="o">}</span> <span class="o">${</span><span class="nv">item</span><span class="o">}</span> <span class="s">-o</span> <span class="o">${</span><span class="nv">output_cpp</span><span class="o">}</span><span class="p">)</span><span class="err">
</span><span class="err"></span>        <span class="nb">endif</span> <span class="p">()</span><span class="err">
</span><span class="err"></span>    <span class="nb">endforeach</span> <span class="p">()</span><span class="err">
</span><span class="err"></span><span class="nb">endfunction</span><span class="p">()</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="nb">get_ui_source</span><span class="p">(</span><span class="o">${</span><span class="nv">UI_FILES</span><span class="o">}</span><span class="p">)</span> <span class="c">#g
</span></code></pre></div><h2 id="ideavim的使用与设置">ideaVim的使用与设置</h2>
<p>关于vim的基本操作，这里就不细讲，网络上大把大把的教程，我这里只讲在CLion中怎么使用vim，怎么配置vim让它在CLion中更好用。</p>
<p>在使用ideaVim前，我们需要先下载 IdeaVim 这个拓展，ideaVim的链接：<a href="https://plugins.jetbrains.com/plugin/164-ideavim" target="_blank" rel="noopener noreffer">https://plugins.jetbrains.com/plugin/164-ideavim</a>，下载好后，应该是默认启用了的。</p>
<p>一、配置ctrl+c和ctrl+v和ctrl+a防止这些你常用的快捷键被vim占用</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/f9e7408182be4b63ad916ef402d265eb.png"
        data-srcset="https://img-blog.csdnimg.cn/f9e7408182be4b63ad916ef402d265eb.png, https://img-blog.csdnimg.cn/f9e7408182be4b63ad916ef402d265eb.png 1.5x, https://img-blog.csdnimg.cn/f9e7408182be4b63ad916ef402d265eb.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/f9e7408182be4b63ad916ef402d265eb.png"
        title="clion8" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/99fe83cb7bc34a31981d1027bcb66553.png"
        data-srcset="https://img-blog.csdnimg.cn/99fe83cb7bc34a31981d1027bcb66553.png, https://img-blog.csdnimg.cn/99fe83cb7bc34a31981d1027bcb66553.png 1.5x, https://img-blog.csdnimg.cn/99fe83cb7bc34a31981d1027bcb66553.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/99fe83cb7bc34a31981d1027bcb66553.png"
        title="clion8" /></p>
<p>二、配置.ideavimrc。</p>
<p>点击 <code>Open ~/.ideavimrc</code> 后，加入下面的配置（这是我个人使用的配置）</p>
<pre><code>let mapleader = &quot;,&quot;
let g:mapleader = &quot;,&quot;
set timeoutlen=300


&quot; general
imap jk &lt;Esc&gt;
imap kj &lt;Esc&gt;
vnoremap q &lt;Esc&gt;
nmap &lt;C-o&gt; :action Back&lt;CR&gt;
nmap &lt;C-i&gt; :action Forward&lt;CR&gt;
nnoremap &lt;Leader&gt;r :&lt;C-u&gt;action RenameElement&lt;CR&gt;

&quot; Redo
nnoremap U &lt;C-r&gt;

&quot; code editing
nnoremap == :&lt;C-u&gt;action ReformatCode&lt;CR&gt;
vnoremap == :&lt;C-u&gt;action ReformatCode&lt;CR&gt;
nnoremap cc :&lt;C-u&gt;action CommentByLineComment&lt;CR&gt;
vnoremap cc :&lt;C-u&gt;action CommentByLineComment&lt;CR&gt;

&quot; Run and debug
nnoremap \r :action RunClass&lt;cr&gt;
nnoremap \i :&lt;C-u&gt;action OptimizeImports&lt;CR&gt;
nnoremap \R :action Run&lt;cr&gt;

nnoremap [[ :action MethodUp&lt;cr&gt;
nnoremap ]] :action MethodDown&lt;cr&gt;
</code></pre><p>加入后点击右上角的小图标进行刷新即可。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/ecedf1c4d61c42c18e39cfd8953226dc.png"
        data-srcset="https://img-blog.csdnimg.cn/ecedf1c4d61c42c18e39cfd8953226dc.png, https://img-blog.csdnimg.cn/ecedf1c4d61c42c18e39cfd8953226dc.png 1.5x, https://img-blog.csdnimg.cn/ecedf1c4d61c42c18e39cfd8953226dc.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/ecedf1c4d61c42c18e39cfd8953226dc.png"
        title="ideavim" /></p>
<p>上述配置文件实现了下面的功能：</p>
<ol>
<li>按下 j+k 或者 k+j 将会退出插入模式。</li>
<li>在可视模式下按q退出。</li>
<li>ctrl+o可以实现指针回退到上一次的位置，ctrl+i前进到上次的位置。可以类比为VS李的前进和后退按钮（一般查看定义查看的比较深，可以使用该命令回退或前进）。</li>
<li>, + r 可以实现CLion中的重构变量名。</li>
<li>U取消撤销（由于vim中按u是撤销，而取消撤销需要ctrl+r，这让人很不习惯）</li>
<li>= + =实现代码格式化。</li>
<li>c + c实现代码注释</li>
<li>[ + [跳转到前一个函数位置</li>
<li>] + ]跳转到下一个函数位置</li>
<li>\ + r 运行当前的可执行程序（如果当前代码段里面有运行按钮的话）</li>
<li>\ + R 运行当前可执行程序，这个是直接相当于按了右上角的三角按钮运行</li>
<li>\ + i 优化导入的包</li>
</ol>
</div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/">CLion开发环境配置完全解析</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-12-29</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-title="CLion开发环境配置完全解析" data-hashtags="CLion开发环境配置完全解析"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-hashtag="CLion开发环境配置完全解析"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-title="CLion开发环境配置完全解析" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-title="CLion开发环境配置完全解析"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-title="CLion开发环境配置完全解析" data-image="https://img-blog.csdnimg.cn/img_convert/c2804a2e21ea79a0b060126b82a9145c.png#pic_center"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-title="CLion开发环境配置完全解析" data-description="CLion开发环境配置完全解析"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-title="CLion开发环境配置完全解析" data-description="CLion开发环境配置完全解析"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/clion%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90/" data-title="CLion开发环境配置完全解析"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/chatgp%E6%95%99%E6%88%91%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90/" class="prev" rel="prev" title="chatgpt教我内存对齐，对齐了但没完全对齐？"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/ejson4cpp%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3/" class="next" rel="next" title="ejson4cpp使用文档">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
